package com.ts.api.http.platform.biz;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gitee.apanlh.util.algorithm.digest.MD5;
import com.gitee.apanlh.util.algorithm.encrypt.symmetric.AES;
import com.gitee.apanlh.util.base.*;
import com.gitee.apanlh.util.dataformat.JsonUtils;
import com.gitee.apanlh.util.valid.ValidParam;
import com.gitee.apanlh.web.model.vo.RequestVO;
import com.ts.api.common.util.H5DomainUrlUtils;
import com.ts.api.http.platform.entity.apply.ApiPlatApplyXinFeng;
import com.ts.api.http.platform.entity.dataexchange.ApiPlatDataExchangeXinFeng;
import com.ts.api.module.api.convert.core.annotation.ApiPlan;
import com.ts.api.module.api.convert.core.annotation.ApiPlanConvertType;
import com.ts.api.module.api.convert.core.entity.ApiApplyParameter;
import com.ts.api.module.api.convert.core.entity.ApiBizStatus;
import com.ts.api.module.api.convert.core.entity.ApiDataExchangeParameter;
import com.ts.api.module.api.convert.core.utils.ApiFieldConverter;
import com.ts.api.module.api.convert.platform.entity.RespPlatformNoticeApply;
import com.ts.api.module.api.convert.platform.entity.RespPlatformPhoneMd5Apply;
import com.ts.api.module.api.convert.platform.entity.RespPlatformPhoneMd5DataExchange;
import com.ts.api.module.api.convert.platform.handler.ApiPlatformPhoneMd5ConvertHandler;
import com.ts.api.module.api.entity.ApiProtocol;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

/**
 * 安心分期（出）&新丰「全&掩码『28
 * 链接：https://www.yuque.com/u21406223/sb8yg0/umt8gfryxoc623qo?singleDoc#
 * 密码：xtlr
 *
 * @author gwc
 * @create 2025-08-22 上午11:11
 */
@ApiPlan(productId = "422", type = ApiPlanConvertType.PLAT_PHONE_MD5)
public class ApiPlatXinFengPhoneMd5 implements ApiPlatformPhoneMd5ConvertHandler {

    private static final String CHANNEL_CODE = "711575515107397";
    private static final String KEY = "aTIftWO19Y07zMPJ";

    @Override
    public Object dataExchange(ApiDataExchangeParameter apiDataExchangeParameter) throws Exception {
        ApiPlatDataExchangeXinFeng xinFengData = new ApiPlatDataExchangeXinFeng();
        // 拓展
        ApiFieldConverter apiFieldConverter = ApiFieldConverter.create(apiDataExchangeParameter);
        // 手机号MD5，32位小写
        xinFengData.setPhoneMd5(apiDataExchangeParameter.getPhoneMd5());
        // 用户姓名，32位小写
        xinFengData.setUserName(MD5.create().digestToHex("默认姓名"));
        // 性别（0-女;1-男（默认））
        Integer sex = ChooseEq.create()
                .when(apiDataExchangeParameter.getSex(), "1", 0)
                .when(apiDataExchangeParameter.getSex(), "0", 1)
                .end(1);
        xinFengData.setSex(sex);
        // 年龄
        xinFengData.setAge(apiFieldConverter.getAgeInt());
        // 用户IP
        if (ValidParam.isNotEmpty(apiDataExchangeParameter.getIp())) {
            xinFengData.setIp(apiDataExchangeParameter.getIp());
        } else {
            xinFengData.setIp("127.0.0.1");
        }
        // 贷款金额(元)
        Integer money = ChooseEq.create()
                .when(apiDataExchangeParameter.getLoanAmount(), "1", 30000)
                .when(apiDataExchangeParameter.getLoanAmount(), "2", 50000)
                .when(apiDataExchangeParameter.getLoanAmount(), "3", 100000)
                .when(apiDataExchangeParameter.getLoanAmount(), "4", 200000)
                .end(30000);
        xinFengData.setLoanMoney(money);
        // 用户所属城市code（可选）
        xinFengData.setCityCode(apiDataExchangeParameter.getAreaCode());
        // 用户所属城市名称（带市，可选）
        xinFengData.setCityName(apiDataExchangeParameter.getCity());
        // 信用情况：0未知  1-有逾期 ；2-无逾期
        Integer overdue = ChooseEq.create()
                .when(apiDataExchangeParameter.getOverdue(), "1", 2)
                .when(apiDataExchangeParameter.getOverdue(), "2", 1)
                .when(apiDataExchangeParameter.getOverdue(), "3", 2)
                .end(0);
        xinFengData.setCredit(overdue);
        // 学历：0-未知；1-初中及以下； 2-高中；3-大专； 4本科；5 研究生及以上
        Integer educationAttainment = ChooseEq.create()
                .when(apiDataExchangeParameter.getEducationAttainment(), "1", 1)
                .when(apiDataExchangeParameter.getEducationAttainment(), "2", 1)
                .when(apiDataExchangeParameter.getEducationAttainment(), "3", 2)
                .when(apiDataExchangeParameter.getEducationAttainment(), "4", 3)
                .when(apiDataExchangeParameter.getEducationAttainment(), "5", 4)
                .when(apiDataExchangeParameter.getEducationAttainment(), "6", 5)
                .end(0);
        xinFengData.setEducation(educationAttainment);
        // 职业信息：1-自由职业者（默认）； 2-上班族； 3-(公务员/事业/国企) ；4-企业主； 5-个体户
        Integer job = ChooseEq.create()
                .when(apiDataExchangeParameter.getCareer(), "1", 2)
                .when(apiDataExchangeParameter.getCareer(), "2", 1)
                .when(apiDataExchangeParameter.getCareer(), "3", 4)
                .when(apiDataExchangeParameter.getCareer(), "4", 3)
                .when(apiDataExchangeParameter.getCareer(), "5", 5)
                .end(1);
        xinFengData.setJob(job);
        // 最低月收入(单位：元）
        Integer monthlySalary = ChooseEq.create()
                .when(apiDataExchangeParameter.getMonthlySalary(), "1", 1000)
                .when(apiDataExchangeParameter.getMonthlySalary(), "2", 3000)
                .when(apiDataExchangeParameter.getMonthlySalary(), "3", 8000)
                .when(apiDataExchangeParameter.getMonthlySalary(), "4", 15000)
                .when(apiDataExchangeParameter.getMonthlySalary(), "5", 30000)
                .end(1000);
        xinFengData.setMinIncome(monthlySalary);
        // 工资发放形式(0无 1银行卡 2现金 3 银行转账 4微信、支付宝）
        Integer salaryPayMethod = ChooseEq.create()
                .when(apiDataExchangeParameter.getSalaryPayMethod(), "1", 1)
                .when(apiDataExchangeParameter.getSalaryPayMethod(), "2", 2)
                .when(apiDataExchangeParameter.getSalaryPayMethod(), "3", 4)
                .end(0);
        xinFengData.setWages(salaryPayMethod);
        // 工龄(上班族、公务员/事业/国企)  0-无 1-(0-6个月) 2-(6-12个月)  3-(12个月以上，可选)
        Integer yearsService = ChooseEq.create()
                .when(apiDataExchangeParameter.getYearsService(), "1", 1)
                .when(apiDataExchangeParameter.getYearsService(), "2", 2)
                .when(apiDataExchangeParameter.getYearsService(), "3", 3)
                .end(0);
        xinFengData.setJobTime(yearsService);
        // 经营流水（具体限制金额-分）（企业主、个体户）
        Integer bizBankDetails = ChooseEq.create()
                .when(apiDataExchangeParameter.getBizBankDetails(), "1", 100000)
                .when(apiDataExchangeParameter.getBizBankDetails(), "2", 500000)
                .when(apiDataExchangeParameter.getBizBankDetails(), "3", 1000000)
                .end(0);
        xinFengData.setIncomeWater(bizBankDetails);
        // 营业执照（0-无  1-两年以下 2-两年以上）
        Integer bizLicenseYear = ChooseEq.create()
                .when(apiDataExchangeParameter.getBizLicenseYear(), "1", 0)
                .when(apiDataExchangeParameter.getBizLicenseYear(), "2", 1)
                .when(apiDataExchangeParameter.getBizLicenseYear(), "3", 2)
                .when(apiDataExchangeParameter.getBizLicenseYear(), "4", 2)
                .end(0);
        xinFengData.setBusLicense(bizLicenseYear);
        // 社保（0-无；1-6个月以下； 2-6个月及以上）
        Integer shebao = ChooseEq.create()
                .when(apiDataExchangeParameter.getSocialSecurity(), "1", 0)
                .when(apiDataExchangeParameter.getSocialSecurity(), "2", 1)
                .when(apiDataExchangeParameter.getSocialSecurity(), "3", 2)
                .when(apiDataExchangeParameter.getSocialSecurity(), "4", 1)
                .end(0);
        xinFengData.setSocial(shebao);
        // 公积金（0-无； 1-.未满6个月 ；2-6个月及以上）
        Integer gongjijin = ChooseEq.create()
                .when(apiDataExchangeParameter.getProvidentFund(), "1", 0)
                .when(apiDataExchangeParameter.getProvidentFund(), "2", 1)
                .when(apiDataExchangeParameter.getProvidentFund(), "3", 2)
                .when(apiDataExchangeParameter.getProvidentFund(), "4", 1)
                .end(0);
        xinFengData.setFund(gongjijin);
        // 房产信息（0-无；1-按揭房产；2-全款房产）
        Integer house = ChooseEq.create()
                .when(apiDataExchangeParameter.getRealEstateInfo(), "1", 0)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "2", 1)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "3", 1)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "4", 1)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "5", 1)
                .when(apiDataExchangeParameter.getRealEstateInfo(), "6", 2)
                .end(0);
        xinFengData.setHouse(house);
        // 车产信息（0-无；1-按揭车；2-全款车）
        Integer car = ChooseEq.create()
                .when(apiDataExchangeParameter.getCarInfo(), "1", 0)
                .when(apiDataExchangeParameter.getCarInfo(), "2", 1)
                .when(apiDataExchangeParameter.getCarInfo(), "3", 2)
                .when(apiDataExchangeParameter.getCarInfo(), "4", 1)
                .end(0);
        xinFengData.setCar(car);
        // 保险保单（0-无；1-1年以内；2-1年以上）
        Integer baodanIs = ChooseEq.create()
                .when(apiDataExchangeParameter.getInsurancePolicy(), "1", 0)
                .when(apiDataExchangeParameter.getInsurancePolicy(), "2", 1)
                .when(apiDataExchangeParameter.getInsurancePolicy(), "3", 2)
                .when(apiDataExchangeParameter.getInsurancePolicy(), "4", 1)
                .end(0);
        xinFengData.setPolicy(baodanIs);
        // 信用卡（0-无；1-2万元以内；2-2万元以上）
        Integer creditLimit = ChooseEq.create()
                .when(apiDataExchangeParameter.getCreditLimit(), "1", 0)
                .when(apiDataExchangeParameter.getCreditLimit(), "2", 1)
                .when(apiDataExchangeParameter.getCreditLimit(), "3", 1)
                .when(apiDataExchangeParameter.getCreditLimit(), "4", 1)
                .when(apiDataExchangeParameter.getCreditLimit(), "5", 2)
                .when(apiDataExchangeParameter.getCreditLimit(), "6", 1)
                .end(0);
        xinFengData.setCreditCard(creditLimit);
        // 芝麻分（0-未知；1-550分以下； 2-550~599； 3-600~649；4-650~699； 5-700分以上）
        Integer zhima = ChooseEq.create()
                .when(apiDataExchangeParameter.getSesameCredit(), "1", 1)
                .when(apiDataExchangeParameter.getSesameCredit(), "2", 3)
                .when(apiDataExchangeParameter.getSesameCredit(), "3", 4)
                .when(apiDataExchangeParameter.getSesameCredit(), "4", 5)
                .end(0);
        xinFengData.setSesame(zhima);
        // 花呗（0-无；1-有）
        Integer hbLimit = ChooseEq.create()
                .when(apiDataExchangeParameter.getHbLimit(), "1", 0)
                .when(apiDataExchangeParameter.getHbLimit(), "2", 1)
                .when(apiDataExchangeParameter.getHbLimit(), "3", 1)
                .when(apiDataExchangeParameter.getHbLimit(), "4", 1)
                .when(apiDataExchangeParameter.getHbLimit(), "5", 1)
                .end(0);
        xinFengData.setHuaBei(hbLimit);
        // 京东白条（0-无；1-有）
        Integer btLimit = ChooseEq.create()
                .when(apiDataExchangeParameter.getBtLimit(), "1", 0)
                .when(apiDataExchangeParameter.getBtLimit(), "2", 1)
                .when(apiDataExchangeParameter.getBtLimit(), "3", 1)
                .when(apiDataExchangeParameter.getBtLimit(), "4", 1)
                .when(apiDataExchangeParameter.getBtLimit(), "5", 1)
                .end(0);
        xinFengData.setBaiTiao(btLimit);
        // 贷款期限（月）
        Integer loanTerm = ChooseEq.create()
                .when(apiDataExchangeParameter.getLoanTerm(), "1", 3)
                .when(apiDataExchangeParameter.getLoanTerm(), "2", 6)
                .when(apiDataExchangeParameter.getLoanTerm(), "3", 12)
                .when(apiDataExchangeParameter.getLoanTerm(), "4", 24)
                .when(apiDataExchangeParameter.getLoanTerm(), "5", 36)
                .when(apiDataExchangeParameter.getLoanTerm(), "6", 60)
                .end(3);
        xinFengData.setTermNum(loanTerm);
        // 贷款用途（0-其他； 1-购房；2-结婚； 3-消费； 4-教育培训；5-购车；6-装修）
        Integer loanPurpose = ChooseEq.create()
                .when(apiDataExchangeParameter.getLoanPurpose(), "1", 0)
                .when(apiDataExchangeParameter.getLoanPurpose(), "2", 4)
                .when(apiDataExchangeParameter.getLoanPurpose(), "3", 2)
                .when(apiDataExchangeParameter.getLoanPurpose(), "4", 6)
                .when(apiDataExchangeParameter.getLoanPurpose(), "5", 0)
                .when(apiDataExchangeParameter.getLoanPurpose(), "6", 3)
                .end(0);
        xinFengData.setPurpose(loanPurpose);
        // 客户端类型（0-未知 1-Android 2-IOS 3-PC）
        xinFengData.setClientType(1);
        // 用户提交申请时间（yyyy-MM-dd HH:mm:ss）
        xinFengData.setApplyTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        // 加密
        AES aes = AES.createEcb(KEY.getBytes());
        String data = aes.encryptToBase64Str(JsonUtils.toJson(xinFengData));
        Map<String, Object> map = MapUtils.newHashMap(newMap -> {
            newMap.put("channelCode", CHANNEL_CODE);
            newMap.put("content", data);
        });
        return JsonUtils.toJson(map);
    }

    @Override
    public RespPlatformPhoneMd5DataExchange respDataExchange(String respJson) throws Exception {
        JSONObject jsonObject = JsonUtils.get(respJson);
        if (jsonObject == null) {
            return RespPlatformPhoneMd5DataExchange.ofFail();
        }
        if(!Eq.object(jsonObject.getInteger("code"), 200)) {
            return RespPlatformPhoneMd5DataExchange.ofFail();
        }
        JSONArray resData = jsonObject.getJSONArray("data");
        if (ValidParam.isEmpty(resData)) {
            return RespPlatformPhoneMd5DataExchange.ofFail();
        }

        RespPlatformPhoneMd5DataExchange result = RespPlatformPhoneMd5DataExchange.ofSuc();

        JSONObject item = resData.getJSONObject(0);
        if (ValidParam.isNotNull(item)) {
            BigDecimal price = item.getBigDecimal("sysSellMoney");
            String companyName = item.getString("companyName");
            String productName = item.getString("productName");
            String logo = item.getString("logoUrl");
            String orderId = item.getString("orderId");

            List<ApiProtocol> protocolList = CollUtils.newArrayList(newList -> {
                //  获取协议
                JSONArray listProtocolResult = item.getJSONArray("authList");
                IteratorUtils.array(listProtocolResult, (protocolResult, index) -> {
                    JSONObject protocolObject = listProtocolResult.getJSONObject(index);
                    ApiProtocol protocol = new ApiProtocol();
                    protocol.setProtocolName(protocolObject.getString("authName"));
                    protocol.setProtocolUrl(protocolObject.getString("authUrl"));
                    newList.add(protocol);
                });
            });

            result.setPrice(price);
            result.setLogoPath(logo);
            result.setDisplayName(companyName);
            result.setProductName(productName);
            result.setApplyId(orderId);
            result.setProtocolList(protocolList);
        }

        return result;
    }

    @Override
    public Object apply(ApiApplyParameter apiApplyParameter) throws Exception {
        ApiPlatApplyXinFeng xinFengData = new ApiPlatApplyXinFeng();
        // 拓展
        ApiFieldConverter apiFieldConverter = ApiFieldConverter.create(apiApplyParameter);
        // 手机号（明文）
        xinFengData.setPhone(apiApplyParameter.getPhone());
        // 订单号
        xinFengData.setOrderId(apiApplyParameter.dataExchangeApplyId());
        // 用户姓名，明文
        xinFengData.setUserName(apiApplyParameter.getUserName());
        // 性别（0-女;1-男（默认））
        Integer sex = ChooseEq.create()
                .when(apiApplyParameter.getSex(), "1", 0)
                .when(apiApplyParameter.getSex(), "0", 1)
                .end(1);
        xinFengData.setSex(sex);
        // 年龄
        xinFengData.setAge(apiFieldConverter.getAgeInt());
        // 用户IP
        if (ValidParam.isNotEmpty(apiApplyParameter.getIp())) {
            xinFengData.setIp(apiApplyParameter.getIp());
        } else {
            xinFengData.setIp("127.0.0.1");
        }
        // 贷款金额(元)
        Integer money = ChooseEq.create()
                .when(apiApplyParameter.getLoanAmount(), "1", 30000)
                .when(apiApplyParameter.getLoanAmount(), "2", 50000)
                .when(apiApplyParameter.getLoanAmount(), "3", 100000)
                .when(apiApplyParameter.getLoanAmount(), "4", 200000)
                .end(30000);
        xinFengData.setLoanMoney(money);
        // 用户所属城市code（可选）
        xinFengData.setCityCode(apiApplyParameter.getAreaCode());
        // 用户所属城市名称（带市，可选）
        xinFengData.setCityName(apiApplyParameter.getCity());
        // 信用情况：0未知  1-有逾期 ；2-无逾期
        Integer overdue = ChooseEq.create()
                .when(apiApplyParameter.getOverdue(), "1", 2)
                .when(apiApplyParameter.getOverdue(), "2", 1)
                .when(apiApplyParameter.getOverdue(), "3", 2)
                .end(0);
        xinFengData.setCredit(overdue);
        // 学历：0-未知；1-初中及以下； 2-高中；3-大专； 4本科；5 研究生及以上
        Integer educationAttainment = ChooseEq.create()
                .when(apiApplyParameter.getEducationAttainment(), "1", 1)
                .when(apiApplyParameter.getEducationAttainment(), "2", 1)
                .when(apiApplyParameter.getEducationAttainment(), "3", 2)
                .when(apiApplyParameter.getEducationAttainment(), "4", 3)
                .when(apiApplyParameter.getEducationAttainment(), "5", 4)
                .when(apiApplyParameter.getEducationAttainment(), "6", 5)
                .end(0);
        xinFengData.setEducation(educationAttainment);
        // 职业信息：1-自由职业者（默认）； 2-上班族； 3-(公务员/事业/国企) ；4-企业主； 5-个体户
        Integer job = ChooseEq.create()
                .when(apiApplyParameter.getCareer(), "1", 2)
                .when(apiApplyParameter.getCareer(), "2", 1)
                .when(apiApplyParameter.getCareer(), "3", 4)
                .when(apiApplyParameter.getCareer(), "4", 3)
                .when(apiApplyParameter.getCareer(), "5", 5)
                .end(1);
        xinFengData.setJob(job);
        // 最低月收入(单位：元）
        Integer monthlySalary = ChooseEq.create()
                .when(apiApplyParameter.getMonthlySalary(), "1", 1000)
                .when(apiApplyParameter.getMonthlySalary(), "2", 3000)
                .when(apiApplyParameter.getMonthlySalary(), "3", 8000)
                .when(apiApplyParameter.getMonthlySalary(), "4", 15000)
                .when(apiApplyParameter.getMonthlySalary(), "5", 30000)
                .end(1000);
        xinFengData.setMinIncome(monthlySalary);
        // 工资发放形式(0无 1银行卡 2现金 3 银行转账 4微信、支付宝）
        Integer salaryPayMethod = ChooseEq.create()
                .when(apiApplyParameter.getSalaryPayMethod(), "1", 1)
                .when(apiApplyParameter.getSalaryPayMethod(), "2", 2)
                .when(apiApplyParameter.getSalaryPayMethod(), "3", 4)
                .end(0);
        xinFengData.setWages(salaryPayMethod);
        // 工龄(上班族、公务员/事业/国企)  0-无 1-(0-6个月) 2-(6-12个月)  3-(12个月以上，可选)
        Integer yearsService = ChooseEq.create()
                .when(apiApplyParameter.getYearsService(), "1", 1)
                .when(apiApplyParameter.getYearsService(), "2", 2)
                .when(apiApplyParameter.getYearsService(), "3", 3)
                .end(0);
        xinFengData.setJobTime(yearsService);
        // 经营流水（具体限制金额-分）（企业主、个体户）
        Integer bizBankDetails = ChooseEq.create()
                .when(apiApplyParameter.getBizBankDetails(), "1", 100000)
                .when(apiApplyParameter.getBizBankDetails(), "2", 500000)
                .when(apiApplyParameter.getBizBankDetails(), "3", 1000000)
                .end(0);
        xinFengData.setIncomeWater(bizBankDetails);
        // 营业执照（0-无  1-两年以下 2-两年以上）
        Integer bizLicenseYear = ChooseEq.create()
                .when(apiApplyParameter.getBizLicenseYear(), "1", 0)
                .when(apiApplyParameter.getBizLicenseYear(), "2", 1)
                .when(apiApplyParameter.getBizLicenseYear(), "3", 2)
                .when(apiApplyParameter.getBizLicenseYear(), "4", 2)
                .end(0);
        xinFengData.setBusLicense(bizLicenseYear);
        // 社保（0-无；1-6个月以下； 2-6个月及以上）
        Integer shebao = ChooseEq.create()
                .when(apiApplyParameter.getSocialSecurity(), "1", 0)
                .when(apiApplyParameter.getSocialSecurity(), "2", 1)
                .when(apiApplyParameter.getSocialSecurity(), "3", 2)
                .when(apiApplyParameter.getSocialSecurity(), "4", 1)
                .end(0);
        xinFengData.setSocial(shebao);
        // 公积金（0-无； 1-.未满6个月 ；2-6个月及以上）
        Integer gongjijin = ChooseEq.create()
                .when(apiApplyParameter.getProvidentFund(), "1", 0)
                .when(apiApplyParameter.getProvidentFund(), "2", 1)
                .when(apiApplyParameter.getProvidentFund(), "3", 2)
                .when(apiApplyParameter.getProvidentFund(), "4", 1)
                .end(0);
        xinFengData.setFund(gongjijin);
        // 房产信息（0-无；1-按揭房产；2-全款房产）
        Integer house = ChooseEq.create()
                .when(apiApplyParameter.getRealEstateInfo(), "1", 0)
                .when(apiApplyParameter.getRealEstateInfo(), "2", 1)
                .when(apiApplyParameter.getRealEstateInfo(), "3", 1)
                .when(apiApplyParameter.getRealEstateInfo(), "4", 1)
                .when(apiApplyParameter.getRealEstateInfo(), "5", 1)
                .when(apiApplyParameter.getRealEstateInfo(), "6", 2)
                .end(0);
        xinFengData.setHouse(house);
        // 车产信息（0-无；1-按揭车；2-全款车）
        Integer car = ChooseEq.create()
                .when(apiApplyParameter.getCarInfo(), "1", 0)
                .when(apiApplyParameter.getCarInfo(), "2", 1)
                .when(apiApplyParameter.getCarInfo(), "3", 2)
                .when(apiApplyParameter.getCarInfo(), "4", 1)
                .end(0);
        xinFengData.setCar(car);
        // 保险保单（0-无；1-1年以内；2-1年以上）
        Integer baodanIs = ChooseEq.create()
                .when(apiApplyParameter.getInsurancePolicy(), "1", 0)
                .when(apiApplyParameter.getInsurancePolicy(), "2", 1)
                .when(apiApplyParameter.getInsurancePolicy(), "3", 2)
                .when(apiApplyParameter.getInsurancePolicy(), "4", 1)
                .end(0);
        xinFengData.setPolicy(baodanIs);
        // 信用卡（0-无；1-2万元以内；2-2万元以上）
        Integer creditLimit = ChooseEq.create()
                .when(apiApplyParameter.getCreditLimit(), "1", 0)
                .when(apiApplyParameter.getCreditLimit(), "2", 1)
                .when(apiApplyParameter.getCreditLimit(), "3", 1)
                .when(apiApplyParameter.getCreditLimit(), "4", 1)
                .when(apiApplyParameter.getCreditLimit(), "5", 2)
                .when(apiApplyParameter.getCreditLimit(), "6", 1)
                .end(0);
        xinFengData.setCreditCard(creditLimit);
        // 芝麻分（0-未知；1-550分以下； 2-550~599； 3-600~649；4-650~699； 5-700分以上）
        Integer zhima = ChooseEq.create()
                .when(apiApplyParameter.getSesameCredit(), "1", 1)
                .when(apiApplyParameter.getSesameCredit(), "2", 3)
                .when(apiApplyParameter.getSesameCredit(), "3", 4)
                .when(apiApplyParameter.getSesameCredit(), "4", 5)
                .end(0);
        xinFengData.setSesame(zhima);
        // 花呗（0-无；1-有）
        Integer hbLimit = ChooseEq.create()
                .when(apiApplyParameter.getHbLimit(), "1", 0)
                .when(apiApplyParameter.getHbLimit(), "2", 1)
                .when(apiApplyParameter.getHbLimit(), "3", 1)
                .when(apiApplyParameter.getHbLimit(), "4", 1)
                .when(apiApplyParameter.getHbLimit(), "5", 1)
                .end(0);
        xinFengData.setHuaBei(hbLimit);
        // 京东白条（0-无；1-有）
        Integer btLimit = ChooseEq.create()
                .when(apiApplyParameter.getBtLimit(), "1", 0)
                .when(apiApplyParameter.getBtLimit(), "2", 1)
                .when(apiApplyParameter.getBtLimit(), "3", 1)
                .when(apiApplyParameter.getBtLimit(), "4", 1)
                .when(apiApplyParameter.getBtLimit(), "5", 1)
                .end(0);
        xinFengData.setBaiTiao(btLimit);
        // 贷款期限（月）
        Integer loanTerm = ChooseEq.create()
                .when(apiApplyParameter.getLoanTerm(), "1", 3)
                .when(apiApplyParameter.getLoanTerm(), "2", 6)
                .when(apiApplyParameter.getLoanTerm(), "3", 12)
                .when(apiApplyParameter.getLoanTerm(), "4", 24)
                .when(apiApplyParameter.getLoanTerm(), "5", 36)
                .when(apiApplyParameter.getLoanTerm(), "6", 60)
                .end(3);
        xinFengData.setTermNum(loanTerm);
        // 贷款用途（0-其他； 1-购房；2-结婚； 3-消费； 4-教育培训；5-购车；6-装修）
        Integer loanPurpose = ChooseEq.create()
                .when(apiApplyParameter.getLoanPurpose(), "1", 0)
                .when(apiApplyParameter.getLoanPurpose(), "2", 4)
                .when(apiApplyParameter.getLoanPurpose(), "3", 2)
                .when(apiApplyParameter.getLoanPurpose(), "4", 6)
                .when(apiApplyParameter.getLoanPurpose(), "5", 0)
                .when(apiApplyParameter.getLoanPurpose(), "6", 3)
                .end(0);
        xinFengData.setPurpose(loanPurpose);
        // 客户端类型（0-未知 1-Android 2-IOS 3-PC）
        xinFengData.setClientType(1);
        // 用户提交申请时间（yyyy-MM-dd HH:mm:ss）
        xinFengData.setApplyTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        // 授权文件信息
        xinFengData.setAuthList(CollUtils.newArrayList(newList -> {
            ApiPlatApplyXinFeng.AuthFile protocolList = new ApiPlatApplyXinFeng.AuthFile();
            protocolList.setAuthName("个人信息授权协议");
            protocolList.setAuthUrl(H5DomainUrlUtils.createUserProtocolUrl(apiApplyParameter.getProductPlanId(), apiApplyParameter.getPhoneMd5()));
            newList.add(protocolList);
        }));
        // 加密
        AES aes = AES.createEcb(KEY.getBytes());
        String data = aes.encryptToBase64Str(JsonUtils.toJson(xinFengData));
        Map<String, Object> map = MapUtils.newHashMap(newMap -> {
            newMap.put("channelCode", CHANNEL_CODE);
            newMap.put("content", data);
        });
        return JsonUtils.toJson(map);
    }

    @Override
    public RespPlatformPhoneMd5Apply respApply(String respJson) throws Exception {
        JSONObject jsonObject = JsonUtils.get(respJson);
        if (jsonObject == null) {
            return RespPlatformPhoneMd5Apply.ofFail();
        }
        if (!Eq.object(jsonObject.getInteger("code"), 200)) {
            return RespPlatformPhoneMd5Apply.ofFail();
        }
        return RespPlatformPhoneMd5Apply.ofSuc();
    }

    @Override
    public RespPlatformNoticeApply parseApplyNotice(RequestVO requestVO) {
        return null;
    }

    @Override
    public Map<String, Object> respApplyNotice(ApiBizStatus apiBizStatus) {
        return Map.of();
    }
}
